interface CheckCondition {
  format: string[];
  size: number;
}
type CheckConditionState = Partial<CheckCondition>;
type ErrorState = 'size' | 'format' | null;

export function beforeUploadCheck(file: File, condition: CheckConditionState): { error: ErrorState; passed: boolean } {
  const { format, size } = condition;
  const isValidFormat = format ? format.includes(file.type) : true;
  const isValidSize = size ? file.size / 1024 / 1024 < size : true;
  let error: ErrorState = null;
  if (!isValidFormat) {
    error = 'format';
  }
  if (!isValidSize) {
    error = 'size';
  }
  return { error, passed: isValidFormat && isValidSize };
}
